#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int a[N];
int n, q;
int binary_search(int x, int y)
{
    int left = 1, right = n;
    while (left < right)
    {
        int mid = (left + right) / 2;
        if (a[mid] < x) left = mid + 1;
        else right = mid;
    }
    if (a[left] < x) return 0;
    int tmp = left;

    left = 1, right = n;

    while (left < right)
    {
        int mid = (left + right + 1) / 2;
        if (a[mid] > y) right = mid - 1;
        else left = mid;
    }
    if (a[left] > y) return 0;
    return right - tmp + 1;
}
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    cin >> q;
    while (q--)
    {
        int x, y; cin >> x >> y;
        cout << binary_search(x, y) << endl;
    }
    return 0;
}